home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 111.1 KB | 3,823 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UGridView.cp
- // Copyright © 1987-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UGRIDVIEW__
- #include "UGridView.h"
- #endif
-
- // MacApp
-
- #ifndef __UADORNERS__
- #include "UAdorners.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- #if qDrag
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
- #endif
-
- #if qDrag
- #ifndef __UDRAGDROP__
- #include "UDragDrop.h"
- #endif
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- // Toolbox
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // These "private" globals have extern interfaces.
-
- RgnHandle pPixelsToHighlight;
- RgnHandle pPreviousSelection;
- RgnHandle pDifference;
- RgnHandle pVisibleCells;
- RgnHandle pInvalidateRgn;
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUGridView:
- //----------------------------------------------------------------------------------------
- #pragma segment GVInit
-
- void InitUGridView()
- {
- #if qTemplateViews
- {
- MA_REGISTER_SIGNATURE(TGridView, kStdGridView);
- MA_REGISTER_SIGNATURE(TTextGridView, kStdTextGridView);
- MA_REGISTER_SIGNATURE(TTextListView, kStdTextListView);
- }
- #endif
-
- pPixelsToHighlight = MakeNewRgn();
- pPreviousSelection = MakeNewRgn();
- pDifference = MakeNewRgn();
- pVisibleCells = MakeNewRgn();
- pInvalidateRgn = MakeNewRgn();
- gUGridViewInitialized = TRUE;
- }
-
-
- //========================================================================================
- // CLASS TRunArray
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment GVOpen
- MA_DEFINE_CLASS_M1(TRunArray,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRunArray constructor
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- TRunArray::TRunArray() :
- fChunks(NULL),
- fLastChunk(0),
- fLastIndex(1),
- fLastItem(0),
- fLastTotal(0),
- fNoOfChunks(0),
- fNoOfItems(0),
- fTotal(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRunArray::IRunArray:
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- void TRunArray::IRunArray()
- {
- IObject();
-
- FailInfo fi;
- Try(fi)
- {
- fChunks = new TDynamicArray;
- fChunks->IDynamicArray(0, sizeof(RunArrayChunk));
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TRunArray::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment GVClose
-
- TRunArray::~TRunArray()
- {
- fChunks = (TDynamicArray*)FreeIfObject(fChunks);// Blow chunks
- }
-
- //----------------------------------------------------------------------------------------
- // TRunArray::DeleteItems:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TRunArray::DeleteItems(short firstItem,
- short noOfItems)
- {
- short num;
- long theTotal;
- short index;
-
- if (!FindChunk(firstItem, num, index, theTotal))
- {
- #if qDebug
- CStr255 theString;
- ConcatNumber("Unable to find chunk for item ", firstItem, theString);
- ProgramBreak(theString);
- #endif
- }
- else
- {
- for (short i = 1; i <= noOfItems; ++i)
- {
- fTotal -= ChunkAt(num).value;
-
- --ChunkAt(num).count;
-
- if (ChunkAt(num).count < index)
- {
- index = 1;
- if (ChunkAt(num).count == 0)
- {
- // need to delete that chunk
- fChunks->DeleteElementsAt(num + 1, 1); // TDynamicArrays are one based (except for [] operator)
- --fNoOfChunks;
-
- // Thanks JDR 10/28/89
- // see if we can consolidate chunks
- if ((num > 0) && (num < fNoOfChunks) && (ChunkAt(num - 1).value == ChunkAt(num).value))
- {
- index = ChunkAt(num - 1).count + 1;
- ChunkAt(num - 1).count += ChunkAt(num).count;
- // need to delete that chunk
- fChunks->DeleteElementsAt(num + 1, 1); // TDynamicArrays are one based (except for [] operator)
- --num;
- --fNoOfChunks;
- }
- }
- else
- ++num;
- }
- }
-
- fNoOfItems -= noOfItems;
-
- // reset the cache
- fLastItem = 0;
- fLastChunk = 0;
- fLastTotal = 0;
- fLastIndex = 1;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TRunArray::FindChunk:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- Boolean TRunArray::FindChunk(short item,
- short& chunk,
- short& indexInChunk,
- long& theTotal)
- {
- Boolean result = FALSE;
-
- short thisItem;
- short count;
- short delta;
-
- if ((fNoOfChunks <= 0) || (item > fNoOfItems) || (item <= 0))
- {
- chunk = 0;
- theTotal = 0;
- indexInChunk = 0;
- item = 0;
- }
- else if (item == fLastItem)
- {
- // check for the very easy case
- chunk = fLastChunk;
- theTotal = fLastTotal;
- indexInChunk = fLastIndex;
-
- result = TRUE;
- }
- else
- {
- delta = abs(item - fLastItem);
-
- if ((delta >= item) || (item <= ChunkAt(0).count))
- {
- // start from the first chunk
- chunk = 0;
- theTotal = 0;
- thisItem = 0;
- }
- else if (delta > (fNoOfItems - item + 1))
- {
- // start from the end chunk
- chunk = fNoOfChunks - 1;
- count = ChunkAt(chunk).count;
- theTotal = fTotal - (count * ChunkAt(chunk).value);
- thisItem = fNoOfItems - count;
- }
- else
- { // start from the previous values
- chunk = fLastChunk;
- theTotal = fLastTotal;
- thisItem = fLastItem - fLastIndex;
- }
-
- if (item > thisItem)
- {
- while ((thisItem + ChunkAt(chunk).count) < item)
- {
- count = ChunkAt(chunk).count;
- theTotal += count * ChunkAt(chunk).value;
- thisItem += count;
- ++chunk;
- }
- }
- else
- {
- do
- {
- --chunk;
- count = ChunkAt(chunk).count;
- theTotal -= count * ChunkAt(chunk).value;
- thisItem -= count;
- } while (thisItem >= item);
- }
- indexInChunk = item - thisItem;
-
- result = TRUE;
- }
- // cache the last values
- fLastItem = item;
- fLastChunk = chunk;
- fLastTotal = theTotal;
- fLastIndex = indexInChunk;
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TRunArray::FindItem:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TRunArray::FindItem(long theTotal)
- {
- short result = 0;
-
- if ((theTotal >= 0) && (theTotal <= fTotal) && (fNoOfChunks > 0))
- if (fNoOfChunks == 1)
- {
- if (ChunkAt(0).value > 0)
- result = (short)Min((theTotal / ChunkAt(0).value) + 1, fNoOfItems);//!!! Cast
- }
- else if (theTotal == 0)
- result = 1;
- else
- {
- ++theTotal;
- short runningCount = 0;
- for (short i = 0; i <= fNoOfChunks - 1; ++i)
- {
- RunArrayChunk chunk = ChunkAt(i);
-
- theTotal -= chunk.value * chunk.count;
- runningCount += chunk.count;
- if (theTotal <= 0)
- {
- result = (short)(runningCount + (theTotal / chunk.value));//!!! Cast
- return result;
- }
- }
- result = fNoOfItems;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TRunArray::GetValue:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TRunArray::GetValue(short item)
- {
- short returnVal = 0;
-
- short num;
- long theTotal;
- short index;
-
- if (fNoOfChunks == 1)
- returnVal = ChunkAt(0).value;
- else if (FindChunk(item, num, index, theTotal))
- returnVal = ChunkAt(num).value;
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TRunArray::InsertItems:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TRunArray::InsertItems(short firstItem,
- short noOfItems,
- short value)
- {
- short num;
- long theTotal;
- short index;
-
- // Check if we can just increment the last size count
- if ((firstItem > fNoOfItems) && (fNoOfChunks > 0) && (ChunkAt(fNoOfChunks - 1).value == value))
- ChunkAt(fNoOfChunks - 1).count += noOfItems;
-
- // check if we can increment any size count
- else if (FindChunk(firstItem, num, index, theTotal) && (ChunkAt(num).value == value))
- ChunkAt(num).count += noOfItems;
-
- // check if this would actually fit as the last item in the previous chunk
- // Thanks Martin Frické, 10/31/89
- else if ((num > 0) && (index == 1) && (ChunkAt(num - 1).value == value))
- ChunkAt(num - 1).count += noOfItems;
-
- // We need to create a new chunk, possibly two
- else
- {
- struct
- {
- RunArrayChunk chunk1;
- RunArrayChunk chunk2;
- } tempChunks;
-
- tempChunks.chunk1.value = value;
- tempChunks.chunk1.count = noOfItems;
-
- if ((index <= 1) || (firstItem > fNoOfItems))
- {
- // need to add one chunk
- if (firstItem > fNoOfItems)
- num = fNoOfChunks; // add a row on the end
-
- fChunks->InsertElementsBefore(num + 1, &tempChunks, 1); // TDynamicArrays are one based (except for [] operator)
- ++fNoOfChunks;
- }
- else
- {
- // need to add two
- tempChunks.chunk2.count = ChunkAt(num).count - index + 1;
- tempChunks.chunk2.value = ChunkAt(num).value;
- ChunkAt(num).count = index - 1;
-
- fChunks->InsertElementsBefore(num + 1 + 1, &tempChunks, 2); // TDynamicArrays are one based (except for [] operator)
- fNoOfChunks += 2;
- }
- }
-
- // reset the cache
- fLastItem = 0;
- fLastChunk = 0;
- fLastTotal = 0;
- fLastIndex = 1;
-
- fNoOfItems += noOfItems;
- fTotal += noOfItems * value;
- }
-
- //----------------------------------------------------------------------------------------
- // TRunArray::SumValues:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- long TRunArray::SumValues(short firstItem,
- short noOfItems)
- {
- long result = 0;
-
- short chunk;
- short indexInChunk;
- long total;
-
- if (fNoOfChunks == 1)
- result = noOfItems * ChunkAt(0).value;
- else if (firstItem == 1)
- {
- if (FindChunk(noOfItems, chunk, indexInChunk, total))
- result = total + (indexInChunk * ChunkAt(chunk).value);
- }
- else if (FindChunk(firstItem, chunk, indexInChunk, total))
- {
- long precedingTotal = total + ((indexInChunk - 1) * ChunkAt(chunk).value);
- if (FindChunk(firstItem + noOfItems - 1, chunk, indexInChunk, total))
- result = total + (indexInChunk * (ChunkAt(chunk).value) - precedingTotal);
- }
-
- return result;
- }
-
-
- //========================================================================================
- // CLASS TGridView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment GVOpen
- MA_DEFINE_CLASS_M1(TGridView,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TGridView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- TGridView::TGridView() :
- fNumOfRows(0),
- fNumOfCols(0),
-
- fAdornRows(FALSE),
- fAdornCols(FALSE),
- fRowInset(0),
- fColInset(0),
- fColWidths(NULL),
- fRowHeights(NULL),
-
- fSelections(NULL),
- fHLRegion(NULL),
- fTemporarySelections(NULL),
-
- fSingleSelection(TRUE)
- {
- }
- // TGridView::TGridView
-
- //----------------------------------------------------------------------------------------
- // TGridView::IGridView:
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- void TGridView::IGridView(TDocument* itsDocument,
- // Its document
- TView* itsSuperView,
- // Its parent view
- const VPoint& itsLocation,
- // Top, Left in parent's coords
- const VPoint& itsSize,
- // Ignored for SizeVariable
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- // Size determiners
- short numOfRows,
- // Number of rows initially
- short numOfCols,
- // Number of columns initially
- short rowHeight,
- // Height of initial rows
- short colWidth,
- // Height of initial columns
- Boolean adornRows,
- // Adornment for Rows?
- Boolean adornCols,
- // Adornment for Columns?
- short rowInset,
- // horizontal space between cells
- short colInset,
- // vertical space between cells
- Boolean singleSelection)// single cell selection?
-
- {
- #if qDebug
- if (!gUGridViewInitialized)
- {
- ProgramBreak("InitUGridView must be called before creating a grid view.");
- Failure(noErr, 0);
- }
- #endif
-
- IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- fAdornRows = adornRows;
- fAdornCols = adornCols;
-
- // Make sure the insets are evenly divided between top/bottom or left/right
- fRowInset = rowInset;
- if (odd(rowInset))
- ++fRowInset;
-
- fColInset = colInset;
- if (odd(colInset))
- ++fColInset;
-
- FailInfo fi;
- Try(fi)
- {
- TRunArray * aRunArray = new TRunArray;
- aRunArray->IRunArray();
- fColWidths = aRunArray;
-
- aRunArray = new TRunArray;
- aRunArray->IRunArray();
- fRowHeights = aRunArray;
-
- fSelections = MakeNewRgn(); // region to hold current selections
- fHLRegion = MakeNewRgn(); // region to hold current highlighted cells
- fTemporarySelections = MakeNewRgn(); // used by SetSelectionRect
-
- fSingleSelection = singleSelection;
-
- if (numOfCols > 0)
- InsColFirst(numOfCols, colWidth);
- if (numOfRows > 0)
- InsRowFirst(numOfRows, rowHeight);
-
- AddAdorner(gSelectionAdorner, kDrawView, FALSE);// wants DoHighlightSelection
-
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- TObject* TGridView::Clone() // override
- {
- MAVolatileInit(TGridView * , aClonedGridView, (TGridView *)(Inherited::Clone()));
-
- aClonedGridView->fNumOfCols = 0;
- aClonedGridView->fNumOfRows = 0;
- aClonedGridView->fColWidths = NULL; // For failure handling
- aClonedGridView->fRowHeights = NULL;
-
- // This code is neccessary because MacApp does not support cloning properly
- // It could be replaced with TGridView(inputView).fColWidths.Clone otherwise
-
- FailInfo fi;
- Try(fi)
- {
- TRunArray * aRunArray = new TRunArray;
- aRunArray->IRunArray();
- aClonedGridView->fColWidths = aRunArray;
-
- aRunArray = new TRunArray;
- aRunArray->IRunArray();
- aClonedGridView->fRowHeights = aRunArray;
-
- aClonedGridView->fSelections = MakeNewRgn();// region to hold current selections
- aClonedGridView->fHLRegion = MakeNewRgn();// region to hold current highlighted cells
- aClonedGridView->fTemporarySelections = MakeNewRgn();// used by SetSelectionRect
-
- if (fNumOfCols > 0)
- aClonedGridView->InsColFirst(fNumOfCols, GetColWidth(1));
- if (fNumOfRows > 0)
- aClonedGridView->InsRowFirst(fNumOfRows, GetRowHeight(1));
-
- fi.Success();
- }
- else // Recover
- {
- aClonedGridView->Free();
- fi.ReSignal();
- }
-
- return aClonedGridView;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment GVClose
-
- TGridView::~TGridView()
- {
- // Dispose regions
- fSelections = DisposeIfRgnHandle(fSelections);
- fHLRegion = DisposeIfRgnHandle(fHLRegion);
- fTemporarySelections = DisposeIfRgnHandle(fTemporarySelections);
-
- fColWidths = (TRunArray *)(FreeIfObject(fColWidths));
- fRowHeights = (TRunArray *)(FreeIfObject(fRowHeights));
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment GVWriteResource
-
- IDType TGridView::GetStandardSignature() // override
- {
- return kStdGridView;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment GVReadResource
-
- void TGridView::ReadFields(TStream* aStream) // override
- {
- #if qDebug
- if (!gUGridViewInitialized)
- {
- ProgramBreak("InitUGridView must be called before creating a grid view.");
- Failure(noErr, 0);
- }
- #endif
-
- short numOfCols,
- numOfRows,
- colWidth,
- rowHeight;
-
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- numOfRows = aStream->ReadInteger();
- numOfCols = aStream->ReadInteger();
-
- rowHeight = aStream->ReadInteger();
- colWidth = aStream->ReadInteger();
-
- fRowInset = aStream->ReadInteger();
- fColInset = aStream->ReadInteger();
-
- fAdornRows = aStream->ReadBoolean();
- fAdornCols = aStream->ReadBoolean();
-
- fSingleSelection = aStream->ReadBoolean();
-
- if (odd(fRowInset))
- ++fRowInset;
-
- if (odd(fColInset))
- ++fColInset;
-
- TRunArray * aRunArray = new TRunArray;
- aRunArray->IRunArray();
- fColWidths = aRunArray;
-
- aRunArray = new TRunArray;
- aRunArray->IRunArray();
- fRowHeights = aRunArray;
-
- fSelections = MakeNewRgn(); // region to hold current selections
- fHLRegion = MakeNewRgn(); // region to hold current highlighted cells
- fTemporarySelections = MakeNewRgn(); // used by SetSelectionRect
-
- if (numOfCols > 0)
- InsColFirst(numOfCols, colWidth);
- if (numOfRows > 0)
- InsRowFirst(numOfRows, rowHeight);
-
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment GVWriteResource
-
- void TGridView::WriteFields(TStream* aStream) // override
- {
- short rowHeight = 0,
- colWidth = 0;
-
- Inherited::WriteFields(aStream);
-
- if (fNumOfRows > 0)
- rowHeight = GetRowHeight(1);
-
- if (fNumOfCols > 0)
- colWidth = GetColWidth(1);
-
- aStream->WriteInteger(fNumOfRows);
- aStream->WriteInteger(fNumOfCols);
- aStream->WriteInteger(rowHeight);
- aStream->WriteInteger(colWidth);
- aStream->WriteInteger(fRowInset);
- aStream->WriteInteger(fColInset);
- aStream->WriteBoolean(fAdornRows);
- aStream->WriteBoolean(fAdornCols);
- aStream->WriteBoolean(fSingleSelection);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::AdornCol:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::AdornCol(short aCol,
- const VRect& area)
- {
- PenNormal();
- CRect qdRect(ViewToQDRect(area));
-
- MoveTo(qdRect.right, qdRect.top);
- Line(0, qdRect.GetLength(vSel));
- if (aCol == 1)
- {
- MoveToPt(qdRect[topLeft]);
- Line(0, qdRect.GetLength(vSel));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::AdornRow:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::AdornRow(short aRow,
- const VRect& area)
- {
- PenNormal();
- CRect qdRect(ViewToQDRect(area));
-
- MoveTo(qdRect.left, qdRect.bottom);
- Line(qdRect.GetLength(hSel), 0);
- if (aRow == 1)
- {
- MoveToPt(qdRect[topLeft]);
- Line(qdRect.GetLength(hSel), 0);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::CalcMinFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- VRect TGridView::CalcMinFrame() // override
- {
- VRect minFrame(Inherited::CalcMinFrame());
-
- // Set the amount of room needed for that many items
- minFrame[botRight] = minFrame[topLeft] + VPoint(fColWidths->GetTotal(), fRowHeights->GetTotal());
-
- return minFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::CanSelectCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- Boolean TGridView::CanSelectCell(GridCell aCell)
- {
- return ((aCell.h >= 1) && (aCell.v >= 1) && (aCell.h <= fNumOfCols) && (aCell.v <= fNumOfRows));
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::CellToVRect:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- VRect TGridView::CellToVRect(GridCell aCell) const
- {
- VRect aRect;
-
- short width;
- short height;
-
- if ((aCell.h < 1) || (aCell.v < 1) || (aCell.h > fNumOfCols) || (aCell.v > fNumOfRows))
- {
- #if qRangeCheck && qDebugMsg
- fprintf(stderr, "aCell.h == %6d fNumOfCols == %6d\n", aCell.h, fNumOfCols);
- fprintf(stderr, "aCell.v == %6d fNumOfRows == %6d\n", aCell.v, fNumOfRows);
- ProgramBreak("Range Check in CellToVRect");
- #endif
-
- aRect = gZeroVRect;
- }
- else // all the params look OK
- {
- width = fColWidths->GetValue(aCell.h);
- if (fColWidths->fNoOfChunks == 1)
- aRect.left = width * (aCell.h - 1);
- else
- aRect.left = fColWidths->SumValues(1, aCell.h - 1);
- aRect.right = aRect.left + width;
-
- height = fRowHeights->GetValue(aCell.v);
- if (fRowHeights->fNoOfChunks == 1)
- aRect.top = height * (aCell.v - 1);
- else
- aRect.top = fRowHeights->SumValues(1, aCell.v - 1);
- aRect.bottom = aRect.top + height;
- }
-
- return aRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::ColToVRect:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- VRect TGridView::ColToVRect(short aCol,
- short numOfCols) const
- {
- VRect aRect;
- long width;
- long leftEdge;
-
- if ((aCol < 1) || (numOfCols < 1) || (aCol + numOfCols - 1 > fNumOfCols))
- {
- #if qDebugMsg && qRangeCheck
- fprintf(stderr, "fNumOfCols == %1d aCol == %1d\n", fNumOfCols, aCol);
- ProgramBreak("Range Check in ColToVRect");
- #endif
-
- aRect = gZeroVRect;
- }
- else // all the params look OK
- {
- if (fColWidths->fNoOfChunks == 1) // only one column width
- {
- width = GetColWidth(1);
- leftEdge = width * (aCol - 1);
- width *= numOfCols;
- }
- else
- {
- leftEdge = fColWidths->SumValues(1, aCol - 1);
- width = fColWidths->SumValues(aCol, numOfCols);
- }
-
- aRect = VRect(leftEdge, 0, leftEdge + width, fRowHeights->GetTotal());
- }
-
- return aRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::AddStrip:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::AddStrip(RgnHandle thePixels,
- VHSelect direction,
- short& startOfStrip,
- short endOfStrip,
- CRect& stripRect,
- short row,
- short col,
- VRect& pixels,
- VRect& previousPixels,
- CRect& prevStripRect)
- {
- if (direction == vSel)
- stripRect = CRect(col, startOfStrip, col, endOfStrip);
- else
- stripRect = CRect(startOfStrip, row, endOfStrip, row);
-
- #if qDebugMsg
- if (gIntenseDebugging)
- {
- fprintf(stderr, "Adding cells = %s\n", (const char*)stripRect);
- }
- #endif
-
- pixels = previousPixels;
-
- if (stripRect.top != prevStripRect.top)
- pixels.top = fRowHeights->SumValues(1, stripRect.top - 1);
- if (stripRect.bottom != prevStripRect.bottom)
- {
- if (stripRect.bottom == stripRect.top)
- pixels.bottom = pixels.top + fRowHeights->GetValue(stripRect.bottom);
- else
- pixels.bottom = fRowHeights->SumValues(1, stripRect.bottom);
- }
- if (stripRect.left != prevStripRect.left)
- pixels.left = fColWidths->SumValues(1, stripRect.left - 1);
- if (stripRect.right != prevStripRect.right)
- {
- if (stripRect.right == stripRect.left)
- pixels.right = pixels.left + fColWidths->GetValue(stripRect.right);
- else
- pixels.right = fColWidths->SumValues(1, stripRect.right);
- }
-
- previousPixels = pixels;
-
- CTemporaryRegion tempRgn;
-
- SetEmptyRgn(tempRgn);
- RectRgn(tempRgn, &ViewToQDRect(pixels));
- UnionRgn(tempRgn, thePixels, thePixels);
-
- prevStripRect = stripRect;
- startOfStrip = 0;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TGridView::CellsToPixels:
- //----------------------------------------------------------------------------------------
- void TGridView::CellsToPixels(RgnHandle theCells,
- RgnHandle thePixels)
- {
- CRect stripRect;
- GridCell aCell;
- short row,
- col;
- VRect pixels;
- VRect previousPixels;
- short startOfStrip;
-
- SetEmptyRgn(thePixels);
-
- if (!EmptyRgn(theCells) && Focus())
- {
- if ((*theCells)->rgnSize == 10) // the region is a rectangle
- {
- CRect cellBounds = (**theCells).rgnBBox;
- pixels = VRect(fColWidths->SumValues(1, cellBounds.left - 1), fRowHeights->SumValues(1, cellBounds.top - 1), fColWidths->SumValues(1, cellBounds.right - 1), fRowHeights->SumValues(1, cellBounds.bottom - 1));
- (*thePixels)->rgnBBox = ViewToQDRect(pixels);
- }
- else
- {
- // Reduce the cells to only those that are visible
- CRect visibleCells;
- VRect visibleVRect(GetVisibleRect());
- visibleCells[topLeft] = VPointToLastCell(visibleVRect[topLeft]);
- visibleCells[botRight] = VPointToLastCell(visibleVRect[botRight]);
- SetRectRgn(pVisibleCells, visibleCells.left, visibleCells.top, visibleCells.right + 1, visibleCells.bottom + 1);
- SectRgn(theCells, pVisibleCells, pVisibleCells);
- CRect cellBounds = (**pVisibleCells).rgnBBox;
-
- CRect prevStripRect = gZeroRect;
- VHSelect direction = LongerSide(cellBounds);
- if (direction == vSel)
- {
- for (col = cellBounds.left; col < cellBounds.right; ++col)
- {
- aCell.h = col;
- startOfStrip = 0;
- for (row = cellBounds.top; row < cellBounds.bottom; ++row)
- {
- aCell.v = row;
- if (PtInRgn(aCell, pVisibleCells))
- {
- if (startOfStrip == 0)
- startOfStrip = row;
- }
- else if (startOfStrip > 0)
- AddStrip(thePixels, direction, startOfStrip, row - 1, stripRect, row, col, pixels, previousPixels, prevStripRect);
- }
- if (startOfStrip > 0)
- AddStrip(thePixels, direction, startOfStrip, cellBounds.bottom - 1, stripRect, row, col, pixels, previousPixels, prevStripRect);
- }
- }
- else
- {
- for (row = cellBounds.top; row < cellBounds.bottom; ++row)
- {
- aCell.v = row;
- startOfStrip = 0;
- for (col = cellBounds.left; col < cellBounds.right; ++col)
- {
- aCell.h = col;
- if (PtInRgn(aCell, pVisibleCells))
- {
- if (startOfStrip == 0)
- startOfStrip = col;
- }
- else if (startOfStrip > 0)
- AddStrip(thePixels, direction, startOfStrip, col - 1, stripRect, row, col, pixels, previousPixels, prevStripRect);
- }
- if (startOfStrip > 0)
- AddStrip(thePixels, direction, startOfStrip, cellBounds.right - 1, stripRect, row, col, pixels, previousPixels, prevStripRect);
- }
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DoHighlightSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::DoHighlightSelection(HLState fromHL,
- HLState toHL)// override
- {
- if (!EmptyRgn(fHLRegion))
- HighlightCells(fHLRegion, fromHL, toHL);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::HighlightCells:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::HighlightCells(RgnHandle theCells,
- HLState fromHL,
- HLState toHL)
- {
- if ((fromHL != toHL) && Focus())
- {
- CellsToPixels(theCells, pPixelsToHighlight);
- SetupDrawingEnvironment();
- switch (fromHL + toHL)
- {
- case hlOffDim:
- PenNormal();
- PenMode(patXor);
- UseSelectionColor();
- FrameRgn(pPixelsToHighlight);
- break;
- case hlOnDim:
- {
- CTemporaryRegion innerRgn;
- CopyRgn(pPixelsToHighlight, innerRgn);
- InsetRgn(innerRgn, 1, 1);
- PenNormal();
- UseSelectionColor();
- InvertRgn(innerRgn);
- }
- break;
- case hlOffOn:
- PenNormal();
- UseSelectionColor();
- InvertRgn(pPixelsToHighlight);
- break;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::DoMenuCommand(CommandNumber aCommandNumber)
- {
- switch (aCommandNumber)
- {
- case cSelectAll:
- {
- CCellIterator iter(this);
-
- for (GridCell aCell = iter.FirstCell(); iter.More(); aCell = iter.NextCell())
- if (CanSelectCell(aCell))
- SelectCell(aCell, kExtend, kHighlight, kSelect);
- break;
- }
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint) // override
- {
- GridCell aCell;
-
- if ((IdentifyPoint(theMouse, aCell) != badChoice) && CanSelectCell(aCell))
- {
- TCellSelectCommand * aCellSelectCommand = new TCellSelectCommand;
- aCellSelectCommand->ICellSelectCommand(this, theMouse, event->IsShiftKeyPressed(), event->IsCommandKeyPressed());
- PostCommand(aCellSelectCommand);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::Draw(const VRect& area) // override
- {
- VRect localArea(area);
-
- if ((fNumOfRows > 0) && (fNumOfCols > 0))
- {
- // make sure we have something to draw
-
- GridCell startCell(VPointToLastCell(area[topLeft]));
- if (fAdornCols)
- startCell.h = (short)Max(1, startCell.h - 1);
- if (fAdornRows)
- startCell.v = (short)Max(1, startCell.v - 1);
- GridCell stopCell(VPointToLastCell(area[botRight]));
-
- VRect aRect(CellToVRect(startCell));
- VRect bRect(CellToVRect(stopCell));
- bRect[topLeft] = aRect[topLeft];
- localArea = bRect;
-
- GridCell startCellToDraw(startCell);
- VRect cellsArea(localArea);
- if (area.top >= aRect.bottom - (fRowInset / 2))//((fRowInset) >> 1)
- {
- ++startCellToDraw.v;
- cellsArea.top += aRect.GetLength(vSel);
- }
-
- DrawRangeOfCells(startCellToDraw, stopCell, cellsArea);
-
- if (fAdornCols)
- {
- short colWidth = 0;
- aRect = localArea;
-
- Boolean constantWidth = fColWidths->fNoOfChunks == 1;
- if (constantWidth) // only one width
- colWidth = GetColWidth(1);
-
- for (long i = startCell.h; i <= stopCell.h; ++i)
- {
- if (constantWidth)
- aRect.right = aRect.left + colWidth;
- else
- aRect.right = aRect.left + GetColWidth(i);
-
- AdornCol(i, aRect);
- aRect.left = aRect.right;
- }
- }
-
- if (fAdornRows)
- {
- short rowHeight = 0;
- aRect = localArea;
-
- Boolean constantHeight = fRowHeights->fNoOfChunks == 1;
- if (constantHeight) // only one height
- rowHeight = GetRowHeight(1);
-
- for (long i = startCell.v; i <= stopCell.v; ++i)
- {
- if (constantHeight)
- aRect.bottom = aRect.top + rowHeight;
- else
- aRect.bottom = aRect.top + GetRowHeight(i);
-
- AdornRow(i, aRect);
- aRect.top = aRect.bottom;
- }
- }
- }
-
- Inherited::Draw(localArea);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DrawRangeOfCells:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::DrawRangeOfCells(GridCell startCell,
- GridCell stopCell,
- const VRect& aRect)
- {
- VCoordinate colWidth;
- VCoordinate rowHeight;
-
- VRect localVRect(aRect); // added because argument is const
- localVRect.left += fColInset / 2;
- localVRect.top += fRowInset / 2;
-
- VCoordinate left = localVRect.left; // save it for each iteration of for loop
-
- if (fColWidths->fNoOfChunks == 1) // only one width
- colWidth = GetColWidth(1);
- if (fRowHeights->fNoOfChunks == 1) // only one height
- rowHeight = GetRowHeight(1);
-
- CTemporaryRegion drawableRegion;
- GetDrawableRegion(drawableRegion);
-
- for (short j = startCell.v; j <= stopCell.v; ++j)
- {
- localVRect.bottom = localVRect.top - fRowInset;
- if (fRowHeights->fNoOfChunks == 1) // only one height
- localVRect.bottom += rowHeight;
- else
- localVRect.bottom += GetRowHeight(j);
-
- localVRect.left = left; // start back at the left for the next row
-
- for (short i = startCell.h; i <= stopCell.h; ++i)
- {
- localVRect.right = localVRect.left - fColInset;
- if (fColWidths->fNoOfChunks == 1) // only one height
- localVRect.right += colWidth;
- else
- localVRect.right += GetColWidth(i);
-
- // check if the rect is drawable
- if (RectInRgn(&ViewToQDRect(localVRect), drawableRegion))
- DrawCell(GridCell(i, j), localVRect);
-
- localVRect.left = localVRect.right + fColInset;
- }
- localVRect.top = localVRect.bottom + fRowInset;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DrawCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::DrawCell(GridCell /* aCell */,
- const VRect& /* aRect */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DelColAt:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::DelColAt(short aCol,
- short numOfCols)
- {
- if ((aCol < 1) || (numOfCols < 1) || (aCol + numOfCols - 1 > fNumOfCols))
- {
- if (numOfCols != 0)
- {
- #if qDebugMsg
- fprintf(stderr, "fNumOfCols == %1d aCol == %1d\n", fNumOfCols, aCol);
- ProgramBreak("Range Check in DelColAt");
- return;
- #endif
-
- }
- }
- else
- {
- VRect aVRect(ColToVRect((short)Max(1, aCol), (short)Max(1, fNumOfCols - aCol + 1)));//!!! cast
- fColWidths->DeleteItems(aCol, numOfCols);
- fNumOfCols -= numOfCols;
-
- AdjustFrame();
- InvalidateVRect(aVRect);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DelRowAt:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::DelRowAt(short aRow,
- short numOfRows)
- {
- if ((aRow < 1) || (numOfRows < 1) || (aRow + numOfRows - 1 > fNumOfRows))
- {
- if (numOfRows != 0)
- {
- #if qDebugMsg
- fprintf(stderr, "fNumOfRows == %1d aRow == %1d\n", fNumOfRows, aRow);
- ProgramBreak("Range Check in DelRowAt");
- return;
- #endif
-
- }
- }
- else
- {
- VRect aVRect(RowToVRect((short)Max(1, aRow), (short)Max(1, fNumOfRows - aRow + 1)));//!!! cast
- fRowHeights->DeleteItems(aRow, numOfRows);
- fNumOfRows -= numOfRows;
-
- AdjustFrame();
- InvalidateVRect(aVRect);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DelColFirst:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::DelColFirst(short numOfCols)
- {
- DelColAt(1, numOfCols);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DelRowFirst:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::DelRowFirst(short numOfRows)
- {
- DelRowAt(1, numOfRows);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DelColLast:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::DelColLast(short numOfCols)
- {
- DelColAt(fNumOfCols - numOfCols + 1, numOfCols);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DelRowLast:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::DelRowLast(short numOfRows)
- {
- DelRowAt(fNumOfRows - numOfRows + 1, numOfRows);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::FirstSelectedCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- GridCell TGridView::FirstSelectedCell()
- {
- CRect bounds;
- GridCell aCell;
- GridCell result;
-
- result = gZeroPt;
- if (IsAnyCellSelected())
- {
- bounds = (*fSelections)->rgnBBox;
- if ((**fSelections).rgnSize == 10) // whole rectangle
- result = bounds[topLeft];
- else
- for (short i = bounds.top; i <= bounds.bottom - 1; ++i)
- {
- aCell.v = i;
- for (short j = bounds.left; j <= bounds.right - 1; ++j)
- {
- aCell.h = j;
- if (PtInRgn(aCell, fSelections))
- {
- result = aCell;
- return result;
- }
- }
- }
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::GetColWidth:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TGridView::GetColWidth(short aCol) const
- {
- #if qRangeCheck && qDebugMsg
- if ((aCol < 1) || (aCol > fNumOfCols))
- {
- fprintf(stderr, "fNumOfCols == &1d aCol == %1d\n", fNumOfCols, aCol);
- ProgramBreak("Range Check in GetColWidth");
- }
- #endif
-
- return ((aCol >= 1) && (aCol <= fNumOfCols)) ? fColWidths->GetValue(aCol) : 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::GetRowHeight:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TGridView::GetRowHeight(short aRow) const
- {
- #if qRangeCheck && qDebugMsg
- if ((aRow < 1) || (aRow > fNumOfRows))
- {
- fprintf(stderr, "fNumOfRows == &1d aRow == %1d\n", fNumOfRows, aRow);
- ProgramBreak("Range Check in GetRowHeight");
- }
- #endif
-
- return ((aRow >= 1) && (aRow <= fNumOfRows)) ? fRowHeights->GetValue(aRow) : 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::InvalidateCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::InvalidateCell(GridCell aCell)
- {
- InvalidateVRect(CellToVRect(aCell));
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::InvalidateSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::InvalidateSelection()
- {
- if (Focus())
- {
- CellsToPixels(fSelections, pInvalidateRgn);
- InvalidateRegion(pInvalidateRgn);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::IdentifyPoint:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- GridViewPart TGridView::IdentifyPoint(const VPoint& thePoint,
- GridCell& aCell)
- {
- GridViewPart aGridViewPart = badChoice; // default value
-
- aCell = VPointToCell(thePoint);
-
- if (aCell != gZeroPt)
- {
- VRect aVRect(CellToVRect(aCell));
- aVRect.Inset(VPoint(fColInset / 2, fRowInset / 2));
- aGridViewPart = inCell;
-
- if (fColInset > 0)
- {
- if (thePoint.h < aVRect.left)
- {
- aGridViewPart = inColumn; // To the left of the cell
- }
- else if (thePoint.h >= aVRect.right)// Remember PtInRgn will report a CPoint
- // as in a region only if the pixel to the
- // right and below the CPoint is contained
- // in the region.
- {
- aGridViewPart = inColumn; // To the right of the cell
- ++aCell.h;
- if (aCell.h > fNumOfCols)
- aGridViewPart = badChoice;
- }
- }
-
- if (fRowInset > 0)
- {
- if (thePoint.v < aVRect.top)
- {
- if (aGridViewPart == inColumn)
- aGridViewPart = inVertex; // Click on both
- else
- aGridViewPart = inRow; // Above the cell
- }
- else if (thePoint.v >= aVRect.bottom)// Remember PtInRgn will report a CPoint
- // as in a region only if the pixel to the
- // right and below the CPoint is contained
- // in the region.
- {
- if (aGridViewPart == inColumn)
- aGridViewPart = inVertex; // Click on both
- else
- aGridViewPart = inRow; // Above the cell
- ++aCell.v;
- if (aCell.v > fNumOfRows)
- aGridViewPart = badChoice;
- }
- }
- }
- return aGridViewPart;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::InsColBefore:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::InsColBefore(short aCol,
- short numOfCols,
- short aWidth)
- {
- if ((aCol < 1) || (numOfCols < 1))
- {
- if (numOfCols != 0)
- {
- #if qDebugMsg && qRangeCheck
- fprintf(stderr, "fNumOfCols == %1d aCol == %1d\n", fNumOfCols, aCol);
- ProgramBreak("Range Check in InsColBefore");
- #endif
-
- }
- }
- else
- {
- fColWidths->InsertItems(aCol, numOfCols, aWidth);
- fNumOfCols += numOfCols;
-
- AdjustFrame();
- InvalidateVRect(ColToVRect((short)Max(1, aCol), (short)Max(1, fNumOfCols - aCol + 1)));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::InsRowBefore:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::InsRowBefore(short aRow,
- short numOfRows,
- short aHeight)
- {
- if ((aRow < 1) || (numOfRows < 1))
- {
- if (numOfRows != 0)
- {
- #if qDebugMsg && qRangeCheck
- fprintf(stderr, "fNumOfRows == %1d aRow == %1d\n", fNumOfRows, aRow);
- ProgramBreak("Range Check in InsRowBefore");
- #endif
-
- }
- }
- else
- {
- fRowHeights->InsertItems(aRow, numOfRows, aHeight);
- fNumOfRows += numOfRows;
-
- AdjustFrame();
- InvalidateVRect(RowToVRect((short)Max(1, aRow), (short)Max(1, fNumOfRows - aRow + 1)));//!!! Cast
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::InsColLast:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::InsColLast(short numOfCols,
- short aWidth)
- {
- InsColBefore(fNumOfCols + 1, numOfCols, aWidth);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::InsRowLast:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::InsRowLast(short numOfRows,
- short aHeight)
- {
- InsRowBefore(fNumOfRows + 1, numOfRows, aHeight);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::InsColFirst:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::InsColFirst(short numOfCols,
- short aWidth)
- {
- InsColBefore(1, numOfCols, aWidth);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::InsRowFirst:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::InsRowFirst(short numOfRows,
- short aHeight)
- {
- InsRowBefore(1, numOfRows, aHeight);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::IsCellSelected:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- Boolean TGridView::IsCellSelected(GridCell aCell)
- {
- return PtInRgn(aCell, fSelections);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::IsAnyCellSelected:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- Boolean TGridView::IsAnyCellSelected()
- {
- return !EmptyRgn(fSelections);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::LastSelectedCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- GridCell TGridView::LastSelectedCell()
- {
- CRect bounds;
- GridCell aCell;
- GridCell result;
-
- result = gZeroPt;
- if (IsAnyCellSelected())
- {
- bounds = (**fSelections).rgnBBox;
- if ((**fSelections).rgnSize == 10) // whole rectangle
- {
- aCell.h = bounds.right - 1;
- aCell.v = bounds.bottom - 1;
- result = aCell;
- }
- else
- for (short i = bounds.bottom - 1; i >= bounds.top; i--)
- {
- aCell.v = i;
- for (short j = bounds.right - 1; j >= bounds.left; j--)
- {
- aCell.h = j;
- if (PtInRgn(aCell, fSelections))
- {
- result = aCell;
- return result;
- }
- }
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::RowToVRect:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- VRect TGridView::RowToVRect(short aRow,
- short numOfRows) const
- {
- VRect aRect;
-
- if ((aRow < 1) || (numOfRows < 1) || (aRow + numOfRows - 1 > fNumOfRows))
- {
- #if qDebugMsg && qRangeCheck
- fprintf(stderr, "fNumOfRows == %1d aRow == %1d\n", fNumOfRows, aRow);
- ProgramBreak("Range Check in RowToVRect");
- #endif
-
- aRect = gZeroVRect;
- }
- else // all the params look OK
- {
- long height;
- long topEdge;
-
- if (fRowHeights->fNoOfChunks == 1) // only one row height
- {
- height = fRowHeights->GetValue(1);
- topEdge = height * (aRow - 1);
- height *= numOfRows;
- }
- else
- {
- topEdge = fRowHeights->SumValues(1, aRow - 1);
- height = fRowHeights->SumValues(aRow, numOfRows);
- }
-
- aRect = VRect(0, topEdge, fColWidths->GetTotal(), topEdge + height);
- }
-
- return aRect;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::ScrollSelectionIntoView:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::ScrollSelectionIntoView(Boolean redraw)
- {
-
- if (IsAnyCellSelected())
- {
- CRect rgnBBox = (**fSelections).rgnBBox;
-
- VRect topLeftRect(CellToVRect(rgnBBox[topLeft]));
- VRect botRightRect(CellToVRect(GridCell(rgnBBox.right - 1, rgnBBox.bottom - 1)));
-
- VRect selectionRect = topLeftRect | botRightRect;
-
- long hCoord = Max(topLeftRect.GetLength(hSel), botRightRect.GetLength(hSel));
- VPoint minToSee(hCoord, Max(topLeftRect.GetLength(vSel), botRightRect.GetLength(vSel)));
-
- RevealRect(selectionRect, minToSee, redraw);
- }
- else
- Inherited::ScrollSelectionIntoView(redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::SetColWidth:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::SetColWidth(short aCol,
- short numOfCols,
- short aWidth)
- {
- #if qDebugMsg
- if ((aCol < 1) || (numOfCols < 1) || (aCol + numOfCols - 1 > fNumOfCols))
- {
- fprintf(stderr, "fNumOfCols == %1d aCol == %1d\n", fNumOfCols, aCol);
- ProgramBreak("Range Check in SetColWidth");
- }
- else
- #endif
-
- if ((fColWidths->fNoOfChunks > 1) || (GetColWidth(1) != aWidth))
- {
- long colMax = Max(1, aCol); // to remove outlined inline warning
-
- // invalidate the old screen area of the cols
- InvalidateVRect(ColToVRect((short)colMax, (short)Max(1, fNumOfCols - aCol + 1)));
-
- // set the new col widths and adjust the view's frame
- fColWidths->DeleteItems(aCol, numOfCols);
- fColWidths->InsertItems(aCol, numOfCols, aWidth);
- AdjustFrame();
-
- // invalidate the new screen area of the cols
- InvalidateVRect(ColToVRect((short)colMax, (short)Max(1, fNumOfCols - aCol + 1)));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::SetRowHeight:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::SetRowHeight(short aRow,
- short numOfRows,
- short aHeight)
- {
- #if qDebugMsg
- if ((aRow < 1) || (numOfRows < 1) || (aRow + numOfRows - 1 > fNumOfRows))
- {
- fprintf(stderr, "fNumOfRows == %1d aRow == %1d\n", fNumOfRows, aRow);
- ProgramBreak("Range Check in SetRowHeight.");
- }
- else
- #endif
-
- if ((fRowHeights->fNoOfChunks != 1) || (GetRowHeight(1) != aHeight))
- {
- long rowMax = Max(1, aRow); // To remove outlined inline warning
-
- // invalidate the old screen area of the rows
- InvalidateVRect(RowToVRect((short)rowMax, (short)Max(1, fNumOfRows - aRow + 1)));
-
- // set the new row height and adjust the view's frame
- fRowHeights->DeleteItems(aRow, numOfRows);
- fRowHeights->InsertItems(aRow, numOfRows, aHeight);
- AdjustFrame();
-
- // invalidate the new screen area of the rows
- InvalidateVRect(RowToVRect((short)rowMax, (short)Max(1, fNumOfRows - aRow + 1)));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::SelectCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::SelectCell(GridCell theCell,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select)
- {
- SetSelectionRect(CRect(theCell, theCell), extendSelection, highlight, select);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::SetEmptySelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::SetEmptySelection(Boolean highlight)
- {
- SetEmptyRgn(fTemporarySelections);
- SetSelection(fTemporarySelections, kDontExtend, highlight, kSelect);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::SetSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::SetSelection(RgnHandle cellsToSelect,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select)
- {
- #if qDebug
- CRect bounds = (**cellsToSelect).rgnBBox;
-
- if (fSingleSelection && ((bounds.GetLength(hSel) > 1) || (bounds.GetLength(vSel) > 1)))
- ProgramBreak("Attempt to select multiple cells when fSingleSelection is true");
- if (!EmptyRgn(cellsToSelect))
- if ((bounds.left < 1) || (bounds.top < 1) || (bounds.right > fNumOfCols + 1) || (bounds.bottom > fNumOfRows + 1))
- ProgramBreak("Attempted selection is outside the range of cells");
- #endif
-
- if (highlight)
- CopyRgn(fSelections, pPreviousSelection);// save the old selection
-
- CTemporaryRegion tempRgn;
-
- SetRectRgn(tempRgn, 1, 1, fNumOfCols + 1, fNumOfRows + 1);
- SectRgn(cellsToSelect, tempRgn, tempRgn);
-
- if (extendSelection && select) // extend the selection region
- UnionRgn(tempRgn, fSelections, fSelections);
- else if (select) // reset the selection region
- CopyRgn(tempRgn, fSelections);
- else // need to de-select the new region
- DiffRgn(fSelections, tempRgn, fSelections);
-
- UserSelectionChanged(this); // so doc updates its designator
-
- CopyRgn(fSelections, fHLRegion);
-
- if (highlight)
- {
- HLState currentHL = GetCurrentHL();
-
- // Turn the deselected cells off
- DiffRgn(pPreviousSelection, fSelections, pDifference);
- HighlightCells(pDifference, currentHL, hlOff);
-
- // Turn the newly selected cells on
- DiffRgn(fSelections, pPreviousSelection, pDifference);
- HighlightCells(pDifference, hlOff, currentHL);
- }
-
- #if qDrag
- if (GetDraggable())
- gDispatcher->InvalidateMouseRegions();
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::SetSelectionRect:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TGridView::SetSelectionRect(const CRect& selectionRect,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select)
-
- {
- if (selectionRect == gZeroRect)
- SetEmptyRgn(fTemporarySelections);
- else
- SetRectRgn(fTemporarySelections, selectionRect.left, selectionRect.top, selectionRect.right + 1, selectionRect.bottom + 1);
-
- SetSelection(fTemporarySelections, extendSelection, highlight, select);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::SetSingleSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TGridView::SetSingleSelection(Boolean theSetting)
- {
- fSingleSelection = theSetting;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::VPointToCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- GridCell TGridView::VPointToCell(const VPoint& aPoint) const
- {
- GridCell aCell(fColWidths->FindItem(aPoint.h), fRowHeights->FindItem(aPoint.v));
-
- return ((aCell.h == 0) || (aCell.v == 0)) ? gZeroPt : aCell;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::VPointToLastCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- GridCell TGridView::VPointToLastCell(const VPoint& aPoint) const
- {
- GridCell aCell;
-
- aCell.h = fColWidths->FindItem(aPoint.h);
- if (aCell.h == 0) // If its invalid, return the last column
- aCell.h = fNumOfCols;
-
- aCell.v = fRowHeights->FindItem(aPoint.v);
- if (aCell.v == 0) // If its invalid, return the last row
- aCell.v = fNumOfRows;
-
- return aCell;
- }
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // TGridView::DoMakeDragCursorRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- RgnHandle TGridView::DoMakeDragCursorRegion()
- {
- RgnHandle dragCursorRegion = NULL;
-
- if (IsAnyCellSelected())
- {
- CTemporaryRegion drawableRgn;
- CTemporaryRegion cellRegion;
-
- dragCursorRegion = MakeNewRgn();
-
- CSelectedCellIterator iter(this);
-
- for (GridCell aCell = iter.FirstCell(); iter.More(); aCell = iter.NextCell())
- {
- RectRgn(cellRegion, &ViewToQDRect(CellToVRect(aCell)));
- UnionRgn(cellRegion, dragCursorRegion, dragCursorRegion);
- }
-
- GetDrawableRegion(drawableRgn); // return the interesection of the selection
- SectRgn(dragCursorRegion, drawableRgn, dragCursorRegion);// and the view's drawable region
- }
-
- return dragCursorRegion;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::WillDrag:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- Boolean TGridView::WillDrag(const VPoint& localMouse,
- const RgnHandle dragCursorRegion)
- {
- Boolean willDrag = (!IsShiftKeyDown() && !IsCommandKeyDown() && Inherited::WillDrag(localMouse, dragCursorRegion));
-
- return willDrag;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DoDragEnter:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TGridView::DoDragEnter()
- {
- fLastTargetCell = gZeroPt;
- fLastCaretTime = 0L;
- fCaretIsShown = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DoDragWithin:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TGridView::DoDragWithin(const VPoint& localMouse)
- {
- GridCell targetCell;
- Boolean targetChanged;
- unsigned long currentTime = TickCount();
-
- targetCell = VPointToLastCell(localMouse);
- targetChanged = (fLastTargetCell != targetCell);
-
- if (targetChanged && fCaretIsShown)
- DrawCellCaret(fLastTargetCell);
-
- if (targetChanged || (currentTime - fLastCaretTime) > GetCaretTime())
- {
- DrawCellCaret(targetCell);
- fLastTargetCell = targetCell;
- fLastCaretTime = currentTime;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DoDragLeave:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TGridView::DoDragLeave()
- {
- if (fCaretIsShown)
- DrawCellCaret(fLastTargetCell);
- }
-
- //----------------------------------------------------------------------------------------
- // TGridView::DrawCellCaret:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TGridView::DrawCellCaret(GridCell targetCell)
- {
- // don't allow a cell in the current selection to be targeted
- if (CanSelectCell(targetCell) && !((TDragDropSession::fgDragDropSession->GetCurrentDragSource() == this) && IsCellSelected(targetCell)))
- {
- PenNormal();
- PenPat(&qd.gray);
- PenMode(notPatXor);
- PenSize(2, 2);
-
- FrameRect(&ViewToQDRect((targetCell == gZeroPt) ? GetDrawableRect() : CellToVRect(targetCell)));
-
- PenNormal();
- }
-
- fCaretIsShown = !fCaretIsShown;
- }
-
- #endif // qDrag
-
- //========================================================================================
- // CLASS TTextGridView
- //========================================================================================
- #undef Inherited
- #define Inherited TGridView
-
- #pragma segment GVOpen
- MA_DEFINE_CLASS_M1(TTextGridView,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTextGridView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- TTextGridView::TTextGridView()
- {
- fTextStyle = gSystemStyle;
- fTextStyleRsrcID = kNoResource;
- fJustification = teFlushDefault;
- fPreferOutline = kDontPreferOutline;
- fLineHeight = 0;
- fLineAscent = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTextGridView::~TTextGridView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::ITextGridView:
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- void TTextGridView::ITextGridView(TDocument* itsDocument,
- // Its document
- TView* itsSuperView,
- // Its parent view
- const VPoint& itsLocation,
- // Top, Left in parent's coords
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- // Size determiners
- short numOfRows,
- // Number of rows initially
- short numOfCols,
- // Number of columns initially
- short rowHeight,
- // Row height, or zero for font height
- short colWidth,
- // Width of items in the columns
- Boolean adornRows,
- // Adornment for Rows?
- Boolean adornCols,
- // Adornment for Columns?
- short rowInset,
- // horizontal space between cells
- short colInset,
- // vertical space between cells
- Boolean singleSelection,
- // single cell selection?
- const TextStyle& itsTextStyle)// size, color, etc. font info
-
- {
- if (rowHeight == 0)
- {
- // Compute the rowHeight for call to IGridView based on the line height and the row inset.
- GrafPtr savedPort;
- GetPort(&savedPort); // save the port
- SetPortWindowPort(gWorkPort); // set port to the work port
-
- SetPortTextStyle(itsTextStyle); // set the port's text style
- PenNormal();
-
- FontInfo theFontInfo;
- rowHeight = MAGetFontInfo(theFontInfo) + rowInset;
-
- SetPort(savedPort); // restore port
- }
-
- IGridView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, numOfRows, numOfCols, rowHeight, colWidth, adornRows, adornCols, rowInset, colInset, singleSelection);
-
- fTextStyle = itsTextStyle;
-
- SetUpFont();
-
- if ((fNumOfCols == 1) && (fSizeDeterminer[hSel] != sizeFixed) && (GetColWidth(1) == 0) && fSuperView)
- SetColWidth(1, fNumOfCols, (short)fSuperView->fSize.h);//!!! Note cast
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment GVWriteResource
-
- IDType TTextGridView::GetStandardSignature() // override
- {
- return kStdTextGridView;
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment GVReadResource
-
- void TTextGridView::ReadFields(TStream* aStream)// override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- fTextStyleRsrcID = aStream->ReadInteger();
- if (fTextStyleRsrcID != kNoResource)
- {
- TextStyle itsTextStyle;
- MAGetTextStyle(fTextStyleRsrcID, itsTextStyle);
- fTextStyle = itsTextStyle;
- }
-
- fPreferOutline = aStream->ReadBoolean();
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
-
- SetUpFont();
-
- if (fNumOfRows > 0)
- if (GetRowHeight(1) == 0) // set row height from font
- SetRowHeight(1, fNumOfRows, fLineHeight + fRowInset);
-
- if ((fNumOfCols == 1) && (fSizeDeterminer[hSel] != sizeFixed) && (GetColWidth(1) == 0))
- SetColWidth(1, fNumOfCols, (short)fSize.h);//!!! Note cast
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment GVWriteResource
-
- void TTextGridView::WriteFields(TStream* aStream)// override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteInteger(fTextStyleRsrcID);
- aStream->WriteBoolean(fPreferOutline);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::DrawCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextGridView::DrawCell(GridCell aCell,
- const VRect& aRect)// override
- {
- CStr255 theText;
- GetText(aCell, theText);
-
- if (GetColWidth(aCell.h) > 0)
- {
- CRect r(ViewToQDRect(aRect));
-
- if (CanSelectCell(aCell))
- MADrawString(theText, r, fJustification, fPreferOutline);
- else
- {
- GrafPtr currentPort;
- GetPort(¤tPort);
-
- PenState pState;
- GetPenState(&pState); // save pen state
- short txMode = currentPort->txMode;
-
- if (qNeedsColorQD || HasColorQD())
- TextMode(grayishTextOr);
-
- MADrawString(theText, r, fJustification, fPreferOutline);
-
- if (!(qNeedsColorQD || HasColorQD()))
- {
- PenPat(&qd.gray);
- PenMode(patBic);
- PaintRect(&r);
- }
-
- SetPenState(&pState); // restore pen state
- TextMode(txMode);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::Focus:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- Boolean TTextGridView::Focus() // override
- {
- if (Inherited::Focus())
- {
- SetPen();
- return TRUE;
- }
- else
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::SetUpFont:
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- void TTextGridView::SetUpFont()
- {
- GrafPtr savedPort;
-
- // set port to the work port
- GetPort(&savedPort);
- SetPortWindowPort(gWorkPort);
-
- { // block for CWhileOutlinePreferred (which has a constructor/destructor)
- CWhileOutlinePreferred setOP(fPreferOutline);
- FontInfo theFontInfo;
-
- SetPen();
- fLineHeight = MAGetFontInfo(theFontInfo);// returns height of font
- fLineAscent = theFontInfo.ascent + (theFontInfo.leading / 2);
- }
-
- // restore port
- SetPort(savedPort);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::SetPen:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextGridView::SetPen()
- {
- TextStyle itsTextStyle = fTextStyle;
- SetPortTextStyle(itsTextStyle);
- PenNormal();
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::GetText:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextGridView::GetText(GridCell /* aCell */,
- CStr255& aString)
- {
- aString.Empty();
- }
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::DoAddDragContent:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTextGridView::DoAddDragContent()
- {
- CFlavorFlags flags;
- TDragItem * dragItem = TDragDropSession::fgDragDropSession->AddDragItem(1);
-
- dragItem->PromiseFlavor('TEXT', flags);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextGridView::DoFulfillPromise:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TTextGridView::DoFulfillPromise(TDragItem* promisedItem)
- {
- switch (promisedItem->GetFlavorType())
- {
- case 'TEXT':
- {
- CSelectedCellIterator iter(this);
- GridCell lastCell = gZeroPt;
- TStream * flavorStream = promisedItem->GetDataStream();
- CStr255 text;
-
- for (GridCell aCell = iter.FirstCell(); iter.More(); aCell = iter.NextCell())
- {
- GetText(aCell, text);
- flavorStream->WriteBytes(&text[1], text.Length());
-
- if (aCell.v > lastCell.v)
- flavorStream->WriteCharacter('\n');
- else
- flavorStream->WriteCharacter('\t');
- lastCell = aCell;
- }
- FreeIfObject(flavorStream);
- }
- break;
-
- default:
- Inherited::DoFulfillPromise(promisedItem);
- break;
- }
- }
-
- #endif // qDrag
-
- //========================================================================================
- // CLASS TTextListView
- //========================================================================================
- #undef Inherited
- #define Inherited TTextGridView
-
- #pragma segment GVOpen
- MA_DEFINE_CLASS_M1(TTextListView,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTextListView::TTextListView: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- TTextListView::TTextListView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTextListView::~TTextListView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::ITextListView:
- //----------------------------------------------------------------------------------------
- #pragma segment GVOpen
-
- void TTextListView::ITextListView(TDocument* itsDocument,
- // Its document
- TView* itsSuperView,
- // Its parent view
- const VPoint& itsLocation,
- // Top, Left in parent's coords
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- // Size determiners
- short numOfItems,
- // Number of items initially
- short rowHeight,
- // Row height, or zero for font height
- short colWidth,
- // Width of items in the columns
- Boolean adornRows,
- // Draw the row adornments?
- Boolean adornCols,
- // Draw the col adornment?
- short rowInset,
- // Amount to inset the rows
- short colInset,
- // Amount to inset the column
- Boolean singleSelection,
- // single cell selection?
- const TextStyle& itsTextStyle)// size, color, etc. font info
-
- {
- ITextGridView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, numOfItems, 1, rowHeight, colWidth, adornRows, adornCols, rowInset, colInset, singleSelection, itsTextStyle);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment GVWriteResource
-
- IDType TTextListView::GetStandardSignature() // override
- {
- return kStdTextListView;
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::CanSelectCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- Boolean TTextListView::CanSelectCell(GridCell aCell)// override
- {
- return (Inherited::CanSelectCell(aCell) && CanSelectItem(aCell.v));
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::CanSelectItem:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- Boolean TTextListView::CanSelectItem(short anItem)
- {
- return ((anItem >= 1) && (anItem <= fNumOfRows));
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::DelItemAt:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TTextListView::DelItemAt(short anItem,
- short numOfItems)
- {
- DelRowAt(anItem, numOfItems);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::DelItemFirst:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TTextListView::DelItemFirst(short numOfItems)
- {
- DelItemAt(1, numOfItems);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::DelItemLast:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TTextListView::DelItemLast(short numOfItems)
- {
- DelItemAt(fNumOfRows - numOfItems + 1, numOfItems);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::DoKeySelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::DoKeySelection(const CStr255& selectionString)
- {
- short lastItemIndex = GetItemIndexOrdered(1);
- CStr255 upperCaseSelectionString(selectionString);
- UprStr255(upperCaseSelectionString);
-
- for (short i = 1; i <= fNumOfRows; i++)
- {
- short itemIndex = GetItemIndexOrdered(i);
-
- CStr255 itemText;
- GetItemText(itemIndex, itemText);
- UprStr255(itemText);
-
- itemText.Delete(upperCaseSelectionString.Length() + 1, itemText.Length() - upperCaseSelectionString.Length());
-
- short compareResult = CPascalStr::CPascalStrCompare(itemText, upperCaseSelectionString);
- if (compareResult > 0)
- break; // the previous index is the closest match
-
- lastItemIndex = itemIndex;
-
- if (compareResult == 0)
- break; // the current index is the closest match
- }
-
- SelectItem(lastItemIndex, FALSE, TRUE, TRUE);
- ScrollSelectionIntoView(TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::FirstSelectedItem:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TTextListView::FirstSelectedItem()
- {
- return FirstSelectedCell().v;
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::GetItemHeight:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TTextListView::GetItemHeight(short anItem)
- {
- return GetRowHeight(anItem);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::GetItemWidth:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TTextListView::GetItemWidth()
- {
- return GetColWidth(1);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::GetItemText:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::GetItemText(short,
- CStr255& aString)
- {
- aString.Empty();
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::GetItemIndexOrdered:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TTextListView::GetItemIndexOrdered(short nthItem)
- {
- return nthItem;
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::GetText:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::GetText(GridCell aCell,
- CStr255& aString) // override
- {
- GetItemText(aCell.v, aString);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::InsItemBefore:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::InsItemBefore(short anItem,
- short numOfItems)
- {
- InsRowBefore(anItem, numOfItems, fLineHeight + fRowInset);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::InsItemFirst:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::InsItemFirst(short numOfItems)
- {
- InsItemBefore(1, numOfItems);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::InsItemLast:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::InsItemLast(short numOfItems)
- {
- InsItemBefore(fNumOfRows + 1, numOfItems);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::InvalidateItem:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::InvalidateItem(short anItem)
- {
- InvalidateCell(GridCell(1, anItem));
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::IsItemSelected:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- Boolean TTextListView::IsItemSelected(short anItem)
- {
- return IsCellSelected(GridCell(1, anItem));
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::LastSelectedItem:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- short TTextListView::LastSelectedItem()
- {
- return LastSelectedCell().v;
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::SetFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TTextListView::SetFrame(const VRect& newFrame,
- Boolean invalidate)// override
- {
- VPoint oldSize(fSize);
-
- Inherited::SetFrame(newFrame, invalidate);
-
- if (fNumOfCols == 1 && fSize != oldSize)
- {
- fColWidths->SetTotal(fColWidths->GetTotal() + fSize.h - fColWidths->ChunkAt(0).value);
- fColWidths->ChunkAt(0).value = (short)fSize.h;//!!! Note cast
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::SelectCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::SelectCell(GridCell theCell,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select) // override
- {
- SelectItem(theCell.v, extendSelection, highlight, select);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::SelectItem:
- //----------------------------------------------------------------------------------------
- #pragma segment GVRes
-
- void TTextListView::SelectItem(short anItem,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select)
- {
- Inherited::SelectCell(GridCell((short)Min(1, anItem), anItem), extendSelection, highlight, select);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::SetItemHeight:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TTextListView::SetItemHeight(short anItem,
- short numOfItems,
- short aHeight)
- {
- SetRowHeight(anItem, numOfItems, aHeight);
- }
-
- //----------------------------------------------------------------------------------------
- // TTextListView::SetItemWidth:
- //----------------------------------------------------------------------------------------
- #pragma segment GVNonRes
-
- void TTextListView::SetItemWidth(short aWidth)
- {
- SetColWidth(1, 1, aWidth);
- }
-
-
- //========================================================================================
- // CLASS TCellSelectCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TTracker
-
- #pragma segment GVSelCommand
- MA_DEFINE_CLASS_M1(TCellSelectCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment GVSelCommand
-
- TCellSelectCommand::TCellSelectCommand()
- {
- fAnchorCell = gZeroPt; // At least set it to something
- fCommandKey = FALSE;
- fDeselecting = FALSE;
- fDifference = NULL;
- fGridView = NULL;
- fPreviousCell = CPoint(-1, -1);
- fPreviousSelection = NULL;
- fShiftKey = FALSE;
- fThisSelection = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand::ICellSelectCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment GVSelCommand
-
- void TCellSelectCommand::ICellSelectCommand(TGridView* itsView,
- const VPoint& itsMouse,
- Boolean theShiftKey,
- Boolean theCommandKey)
- {
- ITracker(cNoCommand, itsView, kCantUndo, kDoesNotCauseChange, NULL, itsView, itsView->GetScroller(kAnySuperView), itsMouse);
- fShiftKey = theShiftKey;
- fCommandKey = theCommandKey;
- fViewConstrain = FALSE;
-
- fGridView = itsView;
-
- FailInfo fi;
- Try(fi)
- {
- fPreviousSelection = MakeNewRgn();
- CopyRgn(fGridView->fSelections, fPreviousSelection);
- fThisSelection = fGridView->fHLRegion;
- SetEmptyRgn(fThisSelection);
- fDifference = MakeNewRgn();
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- TCellSelectCommand::~TCellSelectCommand()
- {
- fPreviousSelection = DisposeIfRgnHandle(fPreviousSelection);
- fDifference = DisposeIfRgnHandle(fDifference);
-
- fThisSelection = NULL; // I don't own it so I don't dispose it.
- // But, I sure don't need a reference to
- // it any more.
- }
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand::ComputeAnchorCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TCellSelectCommand::ComputeAnchorCell(GridCell& clickedCell)
- {
- fAnchorCell = clickedCell;
-
- if (fShiftKey && (!EmptyRgn(fPreviousSelection)))
- {
- const CRect& bounds = (**fPreviousSelection).rgnBBox;
-
- if (fAnchorCell.h >= bounds.left)
- fAnchorCell.h = bounds.left;
- else
- fAnchorCell.h = bounds.right - 1;
- if (fAnchorCell.v >= bounds.top)
- fAnchorCell.v = bounds.top;
- else
- fAnchorCell.v = bounds.bottom - 1;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand::ComputeNewSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TCellSelectCommand::ComputeNewSelection(GridCell& clickedCell)
- {
- if (fGridView->CanSelectCell(clickedCell))
- {
- CRect r;
-
- if (fGridView->fSingleSelection || (!fShiftKey))
- SetRect(r, clickedCell.h, clickedCell.v, clickedCell.h + 1, clickedCell.v + 1);
- else
- {
- Pt2Rect(fAnchorCell, clickedCell, r);
- ++r.right;
- ++r.bottom;
- }
- RectRgn(fThisSelection, r);
- if (fCommandKey && (!fGridView->fSingleSelection))
- if (fDeselecting)
- DiffRgn(fPreviousSelection, fThisSelection, fThisSelection);
- else
- UnionRgn(fPreviousSelection, fThisSelection, fThisSelection);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand::HighlightNewSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TCellSelectCommand::HighlightNewSelection()
- {
- // Turn off previously selected cells
- DiffRgn(fPreviousSelection, fThisSelection, fDifference);
- fGridView->HighlightCells(fDifference, hlOn, hlOff);
-
- // Turn on newly selected cells
- DiffRgn(fThisSelection, fPreviousSelection, fDifference);
- fGridView->HighlightCells(fDifference, hlOff, hlOn);
- }
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand::TrackFeedback:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TCellSelectCommand::TrackFeedback(TrackPhase/* aTrackPhase */ ,
- const VPoint&/* anchorPoint */ ,
- const VPoint&/* previousPoint */ ,
- const VPoint&/* nextPoint */ ,
- Boolean /* mouseDidMove */,
- Boolean /* turnItOn */)// override
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- TTracker* TCellSelectCommand::TrackMouse(TrackPhase aTrackPhase,
- VPoint&/* anchorPoint */ ,
- VPoint&/* previousPoint */ ,
- VPoint& nextPoint,
- Boolean mouseDidMove)// override
- {
- if (mouseDidMove)
- {
- VPoint clippedPoint(nextPoint);
-
- clippedPoint.ConstrainTo(fGridView->GetExtent());
- GridCell clickedCell = fGridView->VPointToCell(clippedPoint);
- if (aTrackPhase == trackBegin)
- {
- ComputeAnchorCell(clickedCell);
- if (fCommandKey)
- fDeselecting = PtInRgn(fAnchorCell, fGridView->fSelections);
- }
-
- if (clickedCell != fPreviousCell)
- {
- ComputeNewSelection(clickedCell);
- HighlightNewSelection();
-
- CopyRgn(fThisSelection, fPreviousSelection);
- fPreviousCell = clickedCell;
- }
- }
- return this;
- }
-
- //----------------------------------------------------------------------------------------
- // TCellSelectCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TCellSelectCommand::DoIt() // override
- {
- if (fGridView->fSingleSelection)
- fGridView->SelectCell(((CRect &)(*fThisSelection)->rgnBBox)[topLeft], kDontExtend, kDontHighlight, kSelect);
- else
- fGridView->SetSelection(fThisSelection, kDontExtend, kDontHighlight, kSelect);
- }
-
-
- //========================================================================================
- // CLASS TRCSelectCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCellSelectCommand
-
- #pragma segment GVSelCommand
- MA_DEFINE_CLASS_M1(TRCSelectCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRCSelectCommand::TRCSelectCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TRCSelectCommand::TRCSelectCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRCSelectCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRCSelectCommand::~TRCSelectCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRCSelectCommand::IRCSelectCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment GVSelCommand
-
- void TRCSelectCommand::IRCSelectCommand(TGridView* itsView,
- const VPoint& itsMouse,
- Boolean theShiftKey,
- Boolean theCommandKey)
- {
- ICellSelectCommand(itsView, itsMouse, theShiftKey, theCommandKey);
- }
-
- //----------------------------------------------------------------------------------------
- // TRCSelectCommand::ComputeNewSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TRCSelectCommand::ComputeNewSelection(GridCell& clickedCell)// override
- {
- if (fGridView->CanSelectCell(clickedCell))
- {
- CRect r;
-
- if (fGridView->fSingleSelection)
- r = CRect(clickedCell.h, clickedCell.v, clickedCell.h + 1, clickedCell.v + 1);
- else
- {
- Pt2Rect(fAnchorCell, clickedCell, r);
- ++r.right;
- ++r.bottom;
- }
- RectRgn(fThisSelection, r);
- if (fCommandKey && (!fGridView->fSingleSelection))
- if (fDeselecting)
- DiffRgn(fPreviousSelection, fThisSelection, fThisSelection);
- else
- UnionRgn(fPreviousSelection, fThisSelection, fThisSelection);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TRCSelectCommand::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- TTracker* TRCSelectCommand::TrackMouse(TrackPhase aTrackPhase,
- VPoint& /* anchorPoint */ ,
- VPoint& /* previousPoint */ ,
- VPoint& nextPoint,
- Boolean mouseDidMove)// override
- {
- if (mouseDidMove)
- {
- VPoint clippedPoint(nextPoint);
- clippedPoint.ConstrainTo(fGridView->GetExtent());
- GridCell clickedCell = fGridView->VPointToCell(clippedPoint);
- if (aTrackPhase == trackBegin)
- {
- ComputeAnchorCell(clickedCell);
- if (fCommandKey)
- fDeselecting = PtInRgn(fAnchorCell, fGridView->fSelections);
- }
-
- if (clickedCell != fPreviousCell)
- {
- if (!fShiftKey && (aTrackPhase != trackBegin))
- {
- ComputeAnchorCell(clickedCell);
- if (fCommandKey)
- fDeselecting = PtInRgn(fAnchorCell, fGridView->fSelections);
- }
- ComputeNewSelection(clickedCell);
- HighlightNewSelection();
-
- CopyRgn(fThisSelection, fPreviousSelection);
- fPreviousCell = clickedCell;
- }
- }
- return this;
- }
-
-
- //========================================================================================
- // CLASS TRowSelectCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TRCSelectCommand
-
- #pragma segment GVSelCommand
- MA_DEFINE_CLASS_M1(TRowSelectCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRowSelectCommand::TRowSelectCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TRowSelectCommand::TRowSelectCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRowSelectCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRowSelectCommand::~TRowSelectCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TRowSelectCommand::IRowSelectCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment GVSelCommand
-
- void TRowSelectCommand::IRowSelectCommand(TGridView* itsView,
- const VPoint& itsMouse,
- Boolean theShiftKey,
- Boolean theCommandKey)
- {
- IRCSelectCommand(itsView, itsMouse, theShiftKey, theCommandKey);
- }
-
- //----------------------------------------------------------------------------------------
- // TRowSelectCommand::ComputeAnchorCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TRowSelectCommand::ComputeAnchorCell(GridCell& clickedCell)// override
- {
- Inherited::ComputeAnchorCell(clickedCell);
- fAnchorCell.h = 1;
- }
-
- //----------------------------------------------------------------------------------------
- // TRowSelectCommand::ComputeNewSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TRowSelectCommand::ComputeNewSelection(GridCell& clickedCell)// override
- {
- clickedCell.h = fGridView->fNumOfCols;
-
- Inherited::ComputeNewSelection(clickedCell);
- }
-
-
- //========================================================================================
- // CLASS TColumnSelectCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TRCSelectCommand
-
- #pragma segment GVSelCommand
- MA_DEFINE_CLASS_M1(TColumnSelectCommand,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TColumnSelectCommand::TColumnSelectCommand: Empty constructor to satisfy the compiler.
- //----------------------------------------------------------------------------------------
- #pragma segment ConstructorRes
-
- TColumnSelectCommand::TColumnSelectCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TColumnSelectCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TColumnSelectCommand::~TColumnSelectCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TColumnSelectCommand::IColumnSelectCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment GVSelCommand
-
- void TColumnSelectCommand::IColumnSelectCommand(TGridView* itsView,
- const VPoint& itsMouse,
- Boolean theShiftKey,
- Boolean theCommandKey)
- {
- IRCSelectCommand(itsView, itsMouse, theShiftKey, theCommandKey);
- }
-
- //----------------------------------------------------------------------------------------
- // TColumnSelectCommand::ComputeAnchorCell:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TColumnSelectCommand::ComputeAnchorCell(GridCell& clickedCell)// override
- {
- Inherited::ComputeAnchorCell(clickedCell);
-
- fAnchorCell.v = 1;
- }
-
- //----------------------------------------------------------------------------------------
- // TColumnSelectCommand::ComputeNewSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment GVDoCommand
-
- void TColumnSelectCommand::ComputeNewSelection(GridCell& clickedCell)// override
- {
- clickedCell.v = fGridView->fNumOfRows;
-
- Inherited::ComputeNewSelection(clickedCell);
- }
-
-
- //========================================================================================
- // CLASS CRowIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CIterator
-
- const short CRowIterator::kNullRow = -1;
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::CRowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CRowIterator::CRowIterator(const TGridView* itsGridView,
- short startRow,
- short stopRow,
- Boolean itsForward)
- {
- IRowIterator(itsGridView, startRow, stopRow, itsForward);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::CRowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CRowIterator::CRowIterator(const TGridView* itsGridView,
- Boolean itsForward)
- {
- IRowIterator(itsGridView, 1, itsGridView->fNumOfRows, itsForward);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::CRowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CRowIterator::CRowIterator(const TGridView* itsGridView)
- {
- IRowIterator(itsGridView, 1, itsGridView->fNumOfRows, kIterateForward);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::IRowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CRowIterator::IRowIterator(const TGridView* itsGridView,
- short startRow,
- short stopRow,
- Boolean itsForward)
- {
- if (itsGridView)
- {
- fFirstRow = (short)Max(1, startRow); //!!! Cast
- fLastRow = (short)Min(itsGridView->fNumOfRows, stopRow);//!!! Cast
- fIterateForward = itsForward;
- Reset(); // this sets it to the beginning
- }
- else
- {
- fFirstRow = kNullRow;
- fLastRow = kNullRow;
- fIterateForward = kIterateForward;
- Reset(); // this sets it to the beginning
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::FirstRow:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- short CRowIterator::FirstRow()
- {
- Reset();
- return fCurrentRow;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::NextRow:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- short CRowIterator::NextRow()
- {
- if (More()) // don't advance if we're at the end of the road!
- Advance();
- return fCurrentRow;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::More:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- Boolean CRowIterator::More()
- {
- return (fCurrentRow != kNullRow);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::Reset:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CRowIterator::Reset()
- {
- if (fFirstRow <= fLastRow)
- fCurrentRow = fIterateForward ? fFirstRow : fLastRow;
- else
- fCurrentRow = kNullRow; // there is nothing to iterate over!
- }
-
- //----------------------------------------------------------------------------------------
- // CRowIterator::Advance:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CRowIterator::Advance()
- {
- //This assumes that More() is false -- otherwise Advance() may start iterating
- //from 0, since kNullRow is most probably less than fLastRow
- if (fIterateForward)
- fCurrentRow = (fCurrentRow < fLastRow) ? fCurrentRow + 1 : kNullRow;
- else
- fCurrentRow = (fCurrentRow > fFirstRow) ? fCurrentRow - 1 : kNullRow;
- }
-
-
- //========================================================================================
- // CLASS CColumnIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CIterator
-
- const short CColumnIterator::kNullColumn = -1;
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::CColumnIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CColumnIterator::CColumnIterator(const TGridView* itsGridView,
- short startColumn,
- short stopColumn,
- Boolean itsForward)
- {
- IColumnIterator(itsGridView, startColumn, stopColumn, itsForward);
- }
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::CColumnIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CColumnIterator::CColumnIterator(const TGridView* itsGridView,
- Boolean itsForward)
- {
- IColumnIterator(itsGridView, 1, itsGridView->fNumOfCols, itsForward);
- }
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::CColumnIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CColumnIterator::CColumnIterator(const TGridView* itsGridView)
- {
- IColumnIterator(itsGridView, 1, itsGridView->fNumOfCols, kIterateForward);
- }
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::IColumnIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CColumnIterator::IColumnIterator(const TGridView* itsGridView,
- short startColumn,
- short stopColumn,
- Boolean itsForward)
- {
- if (itsGridView)
- {
- fFirstColumn = (short)Max(1, startColumn);//!!! Cast
- fLastColumn = (short)Min(itsGridView->fNumOfCols, stopColumn);//!!! Cast
- fIterateForward = itsForward;
- Reset(); // this sets it to the beginning
- }
- else
- {
- fFirstColumn = kNullColumn;
- fLastColumn = kNullColumn;
- fIterateForward = kIterateForward;
- Reset(); // this sets it to the beginning
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::FirstColumn:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- short CColumnIterator::FirstColumn()
- {
- Reset();
- return fCurrentColumn;
- }
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::NextColumn:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- short CColumnIterator::NextColumn()
- {
- if (More()) // don't advance if we're at the end of the road!
- Advance();
- return fCurrentColumn;
- }
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::More:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- Boolean CColumnIterator::More()
- {
- return (fCurrentColumn != kNullColumn);
- }
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::Reset:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CColumnIterator::Reset()
- {
- if (fFirstColumn <= fLastColumn)
- fCurrentColumn = fIterateForward ? fFirstColumn : fLastColumn;
- else
- fCurrentColumn = kNullColumn; // there is nothing to iterate over!
- }
-
- //----------------------------------------------------------------------------------------
- // CColumnIterator::Advance:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CColumnIterator::Advance()
- {
- //This assumes that More() is false -- otherwise Advance() may start iterating
- //from 0, since kNullRow is most probably less than fLastRow
- if (fIterateForward)
- fCurrentColumn = (fCurrentColumn < fLastColumn) ? fCurrentColumn + 1 : kNullColumn;
- else
- fCurrentColumn = (fCurrentColumn > fFirstColumn) ? fCurrentColumn - 1 : kNullColumn;
- }
-
-
- //========================================================================================
- // CLASS CCellIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CIterator
-
- const GridCell CCellIterator::kNullCell = GridCell(-1, -1);
- const Boolean CCellIterator::kIterateRowMajor = TRUE;
-
- //----------------------------------------------------------------------------------------
- // CCellIterator::CCellIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CCellIterator::CCellIterator(const TGridView* itsGridView,
- GridCell startCell,
- GridCell stopCell,
- Boolean itsRowForward,
- Boolean itsColumnForward,
- Boolean itsRowMajor) :
- // initialize the Row and Column Iterators first!
- fRowIterator(itsGridView, startCell.v, stopCell.v, itsRowForward),
- fColumnIterator(itsGridView, startCell.h, stopCell.h, itsColumnForward)
-
- {
- fIterateRowMajor = itsRowMajor; // don't worry about whether or not
- // itsGridView is valid -- let the Row and
- // Column Iterators worry about it.
- }
- // CCellIterator::CCellIterator
-
- //----------------------------------------------------------------------------------------
- // CCellIterator::CCellIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CCellIterator::CCellIterator(const TGridView* itsGridView,
- Boolean itsRowForward,
- Boolean itsColumnForward,
- Boolean itsRowMajor) :
- // initialize the Row and Column Iterators first!
- fRowIterator(itsGridView, itsRowForward),
- fColumnIterator(itsGridView, itsColumnForward)
- {
- fIterateRowMajor = itsRowMajor; // don't worry about whether or not
- // itsGridView is valid -- let the Row and
- // Column Iterators worry about it.
- }
- // CCellIterator::CCellIterator
-
- //----------------------------------------------------------------------------------------
- // CCellIterator::CCellIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CCellIterator::CCellIterator(const TGridView* itsGridView) :
- // initialize the Row and Column Iterators first!
- fRowIterator(itsGridView),
- fColumnIterator(itsGridView)
- {
- fIterateRowMajor = kIterateRowMajor; // don't worry about whether or not
- // itsGridView is valid -- let the Row and
- // Column Iterators worry about it.
- }
- // CCellIterator::CCellIterator
-
- //----------------------------------------------------------------------------------------
- // CCellIterator::FirstCell:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- GridCell CCellIterator::FirstCell()
- {
- Reset();
- return fCurrentCell;
- }
-
- //----------------------------------------------------------------------------------------
- // CCellIterator::NextCell:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- GridCell CCellIterator::NextCell()
- {
- Advance();
- return fCurrentCell;
- }
-
- //----------------------------------------------------------------------------------------
- // CCellIterator::More:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- Boolean CCellIterator::More()
- {
- return (fRowIterator.More() || fColumnIterator.More());
- }
-
- //----------------------------------------------------------------------------------------
- // CCellIterator::Reset:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CCellIterator::Reset()
- {
- fCurrentCell.v = fRowIterator.FirstRow();
- fCurrentCell.h = fColumnIterator.FirstColumn();
- }
-
- //----------------------------------------------------------------------------------------
- // CCellIterator::Advance:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CCellIterator::Advance()
- {
- if (fIterateRowMajor)
- {
- fCurrentCell.h = fColumnIterator.NextColumn();//advance the column
- if (!fColumnIterator.More())
- {
- fCurrentCell.v = fRowIterator.NextRow();//advance the row
- if (fRowIterator.More()) //must go through the columns again
- fCurrentCell.h = fColumnIterator.FirstColumn();
- }
- }
- else
- {
- fCurrentCell.v = fRowIterator.NextRow();//advance the row
- if (!fRowIterator.More())
- {
- fCurrentCell.h = fColumnIterator.NextColumn();//advance the column
- if (fColumnIterator.More()) //must go through the rows again
- fCurrentCell.v = fRowIterator.FirstRow();
- }
- }
- }
-
-
-
- //========================================================================================
- // CLASS CCellInRegionIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CCellIterator
-
- //----------------------------------------------------------------------------------------
- // CCellInRegionIterator::CCellInRegionIterator: an iterator class designed to replace the
- // EachInRegion method of TGridView. APW 7-15
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CCellInRegionIterator::CCellInRegionIterator(const TGridView* itsGridView,
- RgnHandle aRegion,
- Boolean itsRowForward,
- Boolean itsColumnForward,
- Boolean itsRowMajor) :
- CCellIterator(itsGridView, ((CRect &)(*aRegion)->rgnBBox)[topLeft], ((CRect &)(*aRegion)->rgnBBox)[botRight] - CPoint(1, 1), itsRowForward, itsColumnForward, itsRowMajor)
- {
- fIsRectangularRegion = ((**aRegion).rgnSize == 10);// it's a Rectangle
- fRegion = aRegion;
- }
- // CCellInRegionIterator::CCellInRegionIterator
-
- //----------------------------------------------------------------------------------------
- // CCellInRegionIterator::CCellInRegionIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CCellInRegionIterator::CCellInRegionIterator(const TGridView* itsGridView,
- RgnHandle aRegion) :
- CCellIterator(itsGridView, ((CRect &)(*aRegion)->rgnBBox)[topLeft], ((CRect &)(*aRegion)->rgnBBox)[botRight] - CPoint(1, 1), kIterateForward, kIterateForward, kIterateRowMajor)
- {
- fIsRectangularRegion = ((**aRegion).rgnSize == 10);// it's a Rectangle
- fRegion = aRegion;
- }
- // CCellInRegionIterator::CCellInRegionIterator
-
- //----------------------------------------------------------------------------------------
- // CCellInRegionIterator::Reset:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- void CCellInRegionIterator::Reset() //override!
- {
- CCellIterator::Reset(); // should be Inherited::Reset
-
- if (!fIsRectangularRegion) // if it's rectangular, all cells are in
- // the region.
- {
- if ((More()) && !CellIsInRegion()) // Otherwise, check to see if it's in the
- // region.
- Advance(); // This is now guaranteed to be a selected
- // cell
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CCellInRegionIterator::Advance:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
- void CCellInRegionIterator::Advance() //override!
-
- {
- CCellIterator::Advance(); //first advance
-
- if (!fIsRectangularRegion) // do we have to check to see if it is
- // selected?
- {
- while ((More()) && !CellIsInRegion())
- {
- // Yes, so while we have an
- // unselected cell, keep
- // iterating until we
- CCellIterator::Advance(); // run out or find one.
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CCellInRegionIterator::CellIsInRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
- Boolean CCellInRegionIterator::CellIsInRegion()
-
- {
- return PtInRgn(fCurrentCell, fRegion);
- }
-
-
- //========================================================================================
- // CLASS CSelectedCellIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CCellInRegionIterator
-
- //----------------------------------------------------------------------------------------
- // CSelectedCellIterator::CSelectedCellIterator: an iterator class designed to replace the
- // EachSelectedCellDo method of TGridView. APW 7-15
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
- CSelectedCellIterator::CSelectedCellIterator(const TGridView* itsGridView,
- Boolean itsRowForward,
- Boolean itsColumnForward,
- Boolean itsRowMajor) :
- CCellInRegionIterator(itsGridView, itsGridView->fSelections, itsRowForward, itsColumnForward, itsRowMajor)
- {
- }
- // CSelectedCellIterator::CSelectedCellIterator
-
- //----------------------------------------------------------------------------------------
- // CSelectedCellIterator::CSelectedCellIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
- CSelectedCellIterator::CSelectedCellIterator(const TGridView* itsGridView) :
- CCellInRegionIterator(itsGridView, itsGridView->fSelections)
- {
- }
- // CSelectedCellIterator::CSelectedCellIterator
-
- //----------------------------------------------------------------------------------------
- // CSelectedCellIterator::More:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
- void CSelectedCellIterator::Reset()
- {
- // We don't really need to have an override for this method. However
- // doing so fixes a problem with determing the "key function" of the class
- // that leads to duplicate definitions of the VTables in all files that include
- // this iterator or dump files that include it So for the time being use an implementation
- // that just calls inherited.
- Inherited::Reset();
- }
-
- //----------------------------------------------------------------------------------------
- // End of UGridView.cp
-
- #pragma segment Inline
-